package tech.mhuang.pacebox.netty.constans;


/**
 * 常量
 *
 * @author mhuang
 * @since 1.0.0
 */
public class Const {

    public static final int M1 = 10000000;
    public static final int A1 = 20000000;
    public static final int C1 = 30000000;

    public final static int KEY = 123;

    public static void encrypt(byte[] buffer) {
        encrypt(KEY, buffer);
    }

    public static void encrypt(int key, byte[] buffer) {
        int size = buffer.length;
        int idx = 0;
        if (0 == key) {
            key = 1;
        }
        int mkey = M1;
        while (idx < size) {
            key = A1 * (key % mkey) + C1;
            buffer[idx++] ^= ((key >> 20) & 0xff);
        }
    }

    public static byte getCheckCode(byte[] buf) {
        int i = 0;
        int r = 0;
        int size = buf.length;
        for (; i < size; i++) {
            r = (buf[i] ^ r) & 0xff;
        }
        return (byte) r;
    }
}
